// pages/my/my.js
const API = require("../../common/constant.js");
const util = require("../../utils/util");
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    footItem: [
      {
        icon: "../../images/my-follow.png",
        text: "我的关注",
        url: '../myFollowing/myFollowing'
      },
      {
        icon: "../../images/my-fans.png",
        text: "我的粉丝",
        url: '../myFollowers/myFollowers'
      },
      {
        icon: "../../images/my-credit.png",
        text: "信用积分",
        url: '../creditScore/creditScore'
      },
      {
        icon: "../../images/myMoney.png",
        text: "我的诚意金",
        url: '../myMoney/index'
      },
      {
        icon: "../../images/reward.png",
        text: "我的奖品",
        url: '../myAward/index'
      },
      {
        icon: "../../images/myVedio.png",
        text: "我的认证视频",
        url: '../certificateVideo/index'
      },
      {
        icon: "../../images/secret.png",
        text: "隐私",
        url: '../secret/index'
      },
      {
        icon: "../../images/setting.png",
        text: "设置",
        url: '../settings/settings'
      }
    ]
  },
  linkToMember: function (){
    wx.navigateTo({
      url: '../member/index',
    })
  },

  /**
   * 跳到具体的页面  我的关注、粉丝、积分、设置
   */
  toItemInfo: function (e) {
    let currentUrl = this.data.footItem[e.currentTarget.id].url;
    wx.navigateTo({
      url: currentUrl
    })
    // var index  = e.cu
  },

  linkToPage : function(e) {
    if (!app.isPhoneLogin()) {
      app.showUserInfo('您还没有登录，2s后自动为您跳到登录页面', 'none', 1000)
      setTimeout(function () {
        wx.redirectTo({
          url: '../loginAndRegister/loginAndRegister'
        });
      }, 2000)
      return;
    }
    // myPublishEvents
    let urlId = e.currentTarget.dataset.num;
    if(urlId === '0'){
      wx.navigateTo({
        url: '../myPublishEvents/myPublishEvents',
      })
    } else if(urlId === '1'){
      wx.navigateTo({
        url: '../EventRegistration/EventRegistration',
      })
    }else if(urlId === '2') {
      wx.navigateTo({
        url: '../myCollection/myCollection',
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (!app.globalData.hasUserInfo) {
      return;
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () { 
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (!app.globalData.hasUserInfo) {
      app.showUserInfo('请授权，2s后自动跳转首页', 'none', 2000);
      setTimeout(function () {
        wx.switchTab({
          url: '../index/index'
        })
      }, 2000)
      return;
    }
    let wxUserInfo = wx.getStorageSync('wxUserInfo');
    let userInfo = wx.getStorageSync('userInfo');
    if (userInfo) {
      this.setData({
        wxAvatar: userInfo.avatarUrl,
        nickName: userInfo.userName
      })
    }
    else {
      this.setData({
        wxAvatar: wxUserInfo.avatarUrl,
        nickName: wxUserInfo.nickName
      })
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () { 
    
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () { },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () { }
});